﻿#define _CRT_SECURE_NO_WARNINGS 
#include<iostream>
#include<vector>
#include<string>

#include"BSTree.h"


using std::cout;
using std::cin;
using std::endl;


void TestBSTree1()
{
	BSTree<string, string> dict;
	dict.Insert("insert", "插入");
	dict.Insert("erase", "删除");
	dict.Insert("left", "左边");
	dict.Insert("string", "字符串");

	string str;
	while (cin >> str)
	{
		auto ret = dict.Find(str);
		if (ret)
		{
			cout << str << ":" << ret->_value << endl;
		}
		else
		{
			cout << "单词拼写错误" << endl;
		}
	}
}

void TestBSTree2()
{
	//string strs[] = { "苹果", "西瓜", "苹果", "樱桃", "苹果",
	//	"樱桃", "苹果", "樱桃", "苹果" };
	//// 统计水果出现的次
	string strs[] = { "abc", "abcd", "def", "abca", "def","abc","def"
		,"deff","deff","deff" };
	BSTree<string, int> countTree;
	for (auto str : strs)
	{
		auto ret = countTree.Find(str);
		if (ret == nullptr)
		{
			countTree.Insert(str, 1);
		}
		else
		{
			ret->_value++;
		}
	}
	countTree.InOrder();
	cout << endl;
	countTree.Erase("abcd");
	countTree.Erase("abc");
	countTree.Erase("def");
	countTree.InOrder();
	cout << endl;

}

void TestBSTree3()
{
	//string strs[] = { "苹果", "西瓜", "苹果", "樱桃", "苹果",
	//	"樱桃", "苹果", "樱桃", "苹果" };
	//// 统计水果出现的次
	string strs[] = { "abc", "abcd", "def", "abca", "def","abc","def"
		,"deff","deff","deff" };
	BSTree<string, int> countTree;
	for (auto str : strs)
	{
		auto ret = countTree.Find(str);
		if (ret == nullptr)
		{
			countTree.InsertR(str, 1);
		}
		else
		{
			ret->_value++;
		}
	}
	countTree.InOrder();
	cout << endl;
	countTree.EraseR("abcd");
	countTree.EraseR("abc");
	countTree.EraseR("def");

	countTree.InOrder();
	cout << endl;

}
int main()
{
	TestBSTree3();
    return 0;
}